var g_GameZOder={bg:0,ui:1,front:100};
var g_GameStatus={normal:0,stop:1,gameOver:2};

var GameScene =cc.Scene.extend({
	gameLayer:null,
	mushroom:null,
	leafList:[],
	acornList:[],
	flowerList:[],
	onEnter:function(){
		this._super();
		this.initData();
		this.bear.beginRotate();
		this.schedule(this.update,0);
	},

	//==
	//初始化数据
	//==
	initData:function(){
		//后面为进入场景后的动作
		//添加Layer
		this.gameLayer=cc.Layer.create();
		this.addChild(this.gameLayer);
		//添加背景
		var bg=cc.Sprite.create(s_forest1);
		bg.setAnchorPoint(cc.p(0,0));
		this.gameLayer.addChild(bg,g_GameZOder.bg);
		//设置背景的描点和位置
		//bg.setPosition(cc.p(0,0));
		//添加蘑菇
		this.mushroom=new MushroomSprite();
		this.mushroom.setAnchorPoint(cc.p(0.5,0));
		this.mushroom.setPosition(cc.p(240,0));
		this.gameLayer.addChild(this.mushroom,g_GameZOder.ui);
		//添加熊
		this.bear=new BearSprite();
		this.bear.setPosition(cc.p(240,60));
		this.gameLayer.addChild(this.bear,g_GameZOder.ui);

		//初始化奖品
		this.initAcorn();
		this.initFlower();
		this.initLeaf();
	},

	update:function(dt){
		//dt为每帧消耗的时间
		this.bear.update(dt);
		this.bear.collide(this.mushroom);

		//判断熊与叶子的碰撞
		for(var i=0;i<this.leafList.length;i++){
			var prize=this.leafList[i];
			if(!prize.isHit){
				if(this.bear.collide(prize)){
					prize.setVisible(false);
					prize.isHit=true;
				}
			}
		}
		
		//与花
		for(var i=0;i<this.flowerList.length;i++){
			var prize=this.flowerList[i];
			if(!prize.isHit){
				if(this.bear.collide(prize)){
					prize.setVisible(false);
					prize.isHit=true;
				}
			}
		}

		//与橡子
		for(var i=0;i<this.acornList.length;i++){
			var prize=this.acornList[i];
			if(!prize.isHit){
				if(this.bear.collide(prize)){
					prize.setVisible(false);
					prize.isHit=true;
				}
			}
		}
		

	},

	//初始化橡子
	initAcorn:function(){
		var left=0;
		var space=30;
		for(var i=1;i<=15;i++){
			var prize=new AcornPrize();
			prize.initData();
			prize.setPosition(cc.p(left+i*space,270));
			this.gameLayer.addChild(prize,g_GameZOder.ui);
			this.acornList.push(prize);
		}
	},

	//初始化花
	initFlower:function(){
		var left=30;
		var space=30;
		for(var i=1;i<=13;i++){
			var prize=new FlowerPrize();
			prize.initData();
			prize.setPosition(cc.p(left+i*space,245));
			this.gameLayer.addChild(prize,g_GameZOder.ui);
			this.flowerList.push(prize);
		}
	},
		
	//初始化叶子
	initLeaf:function(){
		var left=60;
		var space=30;
		for(var i=1;i<=11;i++){
			var prize=new LeafPrize();
			prize.initData();
			prize.setPosition(cc.p(left+i*space,220));
			this.gameLayer.addChild(prize,g_GameZOder.ui);
			this.leafList.push(prize);
		}
	},
});
